package com.jiawa.train.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.jiawa.train.batch.controller.TestController;
import com.jiawa.train.batch.feign.BusinessFeign;
import com.jiawa.train.common.resp.CommonResp;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@EnableScheduling
public class DailyTrainJob implements Job {
	private static final Logger LOG = LoggerFactory.getLogger(TestController.class);

	@Autowired
	BusinessFeign businessFeign;
	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));

		LOG.info("生成15天后的车次数据开始！");
		Date date = new Date();
		DateTime dateTime = DateUtil.offsetDay(date, -15);
		Date offsetDate = dateTime.toJdkDate();
		CommonResp<Object> commonResp = businessFeign.genDaily(offsetDate);
		LOG.info("生成每日车次数据结束！，结果：{}",commonResp);
	}
}
